package com.example.teaching_server.controller;

import com.example.teaching_server.common.ApiResponse;
import com.example.teaching_server.dto.SidebarDTO;
import com.example.teaching_server.service.SidebarService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/api/sidebar")
@RequiredArgsConstructor
@Tag(name = "侧边栏管理", description = "通用侧边栏数据查询接口")
public class SidebarController {

    private final SidebarService sidebarService;

    /**
     * 获取侧边栏数据
     */
    @GetMapping
    @Operation(summary = "获取侧边栏数据", description = "获取通用侧边栏相关数据")
    public ApiResponse<SidebarDTO> getSidebarData() {
        log.info("开始获取侧边栏数据");

        try {
            SidebarDTO data = sidebarService.getSidebarData();
            log.info("侧边栏数据获取成功");
            return ApiResponse.success("侧边栏数据获取成功", data);
        } catch (Exception e) {
            log.error("获取侧边栏数据失败", e);
            return ApiResponse.fail("获取侧边栏数据失败: " + e.getMessage());
        }
    }
}
